﻿using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Threading;
using GalaSoft.MvvmLight.Command;
using XamlingCore.Infrastructure.Dialog;

using XamlingCore.Infrastructure.View.DialogView;
using XamlingCore.Infrastructure.View.Implementation;
using XamlingCore.Infrastructure.View.Interface;


namespace XamlingCore.Infrastructure.View
{
    public class ViewModelBase : NotifyBase
    {
        private DialogViewModelBase currentDialogViewModel;

        public ViewModelBase()
        {
            //currentDialogViewModel = new DialogViewModelBase();
        }

        public virtual void ShowDialog(ShowDialogViewModelBase dialogViewModel, System.TimeSpan timeOut, System.Action<Dialog.DialogResult> dialogResult)
        {
            currentDialogViewModel.ShowDialog(dialogViewModel, timeOut, dialogResult);
        }

        public virtual void HideDialog()
        {
            currentDialogViewModel.HideDialog();
        }

        protected void SetActive(object obj, bool isActive)
        {
            var activeAware = obj as IActiveAware;
            if (activeAware != null)
            {
                activeAware.IsActive(false);
            }
        }

        public bool IsOutOfBrowser
        {
            get
            {
                return Application.Current.IsRunningOutOfBrowser;
            }
        }

        public bool IsInstalled
        {
            get
            {
                return Application.Current.InstallState == InstallState.Installed;
            }
        }

        public bool IsOutOfBrowserAndFullTrust
        {
            get { return IsFullTrust && IsOutOfBrowser; }
        }

        public bool IsFullTrust
        {
            get
            {
                return Application.Current.HasElevatedPermissions;
            }
        }

        public DialogViewModelBase DialogViewModel
        {
            get { return currentDialogViewModel; }
            set
            {
                currentDialogViewModel = value;
                OnPropertyChanged("DialogViewModel");
            }
        }


    }
}
